<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" >
    <head lang="en">
        <title>Add Corpus</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script src="//hm.baidu.com/hm.js?3cfaa114cca90dbeb8cf6908074f92ef"></script>
        <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all"/>
        <script type="text/javascript" th:src="@{/lib/layui/layui.js}"/>
        <script type="text/javascript" th:inline="javascript">
            /*<![CDATA[*/
            var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;
            //--------------------------------------------------------------
            layui.use(['layedit'], function() {
                //创建一个编辑器
                var $ = layui.$;
                var layedit = layui.layedit;
                layedit.set({
                    uploadImage: {
                        url: basePath + '/image/uploadImage?pid=0'//接口url
                        , type: 'post' //默认post
                    }
                });
                var schemeIndex = layedit.build('scheme_editor');
                layedit.sync(schemeIndex);//这样同步不了，只是初始化同步了一下

                $(document).ready(function() {
                    $("#add").click(function() {
                        console.info("update: add status");

                        if($("#key").val().trim()==""
                            || $("#name").val().trim()==""
                            || $("#summary").val().trim()==""
                            || $("#description").val().trim()==""
                            || $("#supporter").val().trim()==""
                            || $("#reporter").val().trim()==""){
                            return
                        }
                        schemeContext = layedit.getContent(schemeIndex) //获取html
                        scheme = layedit.getText(schemeIndex) // 获取纯文本
                        console.info(layedit.getContent(schemeIndex))
                        console.info(layedit.getText(schemeIndex))
                        if(scheme.trim()==""){
                            layer.msg('请输入解答方案.');
                            return
                        }
                        key = $("#key").val().trim();
                        summary = $("#summary").val().trim();
                        description = $("#description").val().trim();

                        name = $("#name").val().trim();
                        supporter = $("#supporter").val().trim();
                        reporter = $("#reporter").val().trim();

                        var paratmeter = {
                            "id" : parseInt($("#id").val()),
                            "key" : key,
                            "name" : name,
                            "reporter" : reporter,
                            "supporter" : supporter,
                            "scheme" : scheme,
                            "schemeContext" : schemeContext,
                            "summary" : summary,
                            "description" : description
                        };
                        console.log(JSON.stringify(paratmeter));
                        $.ajax({
                            contentType:"application/json;charset=utf-8",
                            url : basePath+ "/project/addProject",
                            type : "post",
                            data : JSON.stringify(paratmeter),
                            dataType : "json",
                            success : function(data) {
                                if(data.hasOwnProperty('code')){
                                    console.log(data);
                                    if(data.code==0){
//                                        alert("添加成功...");
                                        layer.msg('添加成功.');
                                    }else {
//                                        alert("添加失败...");
                                        layer.msg('添加失败.');
                                    }
                                }
                            },
                            error:function(){ }
                        });
                    });
                });
            });
            /*]]>*/
        </script>
    </head>
    <body>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>添加相关问题</legend>
        </fieldset>

        <div class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">Key</label>
                <div class="layui-input-inline">
                    <input type="text" id="key" name="key" lay-verify="required" autocomplete="off" placeholder="请输入问题标识" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入项目名称" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">问题摘要</label>
                <div class="layui-input-block">
                    <textarea id="summary" name="summary" lay-verify="required" placeholder="请输入问题摘要" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">问题描述</label>
                <div class="layui-input-block">
                    <textarea id="description" name="description" lay-verify="required" placeholder="请输入问题描述" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">解决方案</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea layui-hide" id="scheme_editor" name="schemeContext" lay-verify="context" placeholder="请输入解决方案"></textarea>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">报告人</label>
                <div class="layui-input-inline">
                    <input type="text" id="reporter" name="reporter" lay-verify="required" placeholder="请输入报告人" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">支持人</label>
                <div class="layui-input-inline">
                    <input type="text" id="supporter" name="supporter" lay-verify="required" placeholder="请输入支持人" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" id="add">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </body>
</html>